# Simple Git Sync Script
param(
    [string]$Action = "status"
)

Write-Host "Git Sync Tool" -ForegroundColor Green
Write-Host "=============" -ForegroundColor Green
Write-Host ""

if (!(Test-Path ".git")) {
    Write-Host "Error: Not a git repository" -ForegroundColor Red
    Write-Host "Please run: git init" -ForegroundColor Yellow
    return
}

if ($Action -eq "push") {
    Write-Host "Adding files..." -ForegroundColor Cyan
    git add .
    
    Write-Host "Committing changes..." -ForegroundColor Cyan
    git commit -m "Update - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
    
    Write-Host "Pushing to remote..." -ForegroundColor Cyan
    git push --set-upstream origin master
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Push completed!" -ForegroundColor Green
    } else {
        Write-Host "Push failed" -ForegroundColor Red
    }
} elseif ($Action -eq "pull") {
    Write-Host "Pulling latest changes..." -ForegroundColor Cyan
    git pull origin master
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Pull completed!" -ForegroundColor Green
    } else {
        Write-Host "Pull failed" -ForegroundColor Red
    }
} else {
    Write-Host "Git Status:" -ForegroundColor Cyan
    git status
    Write-Host ""
    Write-Host "Recent commits:" -ForegroundColor Cyan
    git log --oneline -5
}

Write-Host ""
Write-Host "Done!" -ForegroundColor Green
